import {
    adminSystemIndexAPI
} from '@/api/admin/config'
import { configHeaderModelSortAPI } from '@/api/config'
const init = {
    state: {
        orgId: localStorage.getItem('orgId'),
        companyLoginImg: localStorage.getItem('companyLoginImg'),
        companyLoginLogo: localStorage.getItem('companyLoginLogo'),
        companyLogo: localStorage.getItem('companyLogo'),
        companyName: localStorage.getItem('companyName'),
    },

    mutations: {
        SET_ORGID: (state, orgId) => {
            state.orgId = orgId
            localStorage.setItem('orgId', orgId)
        },
        // 登录页背景图
        SET_COMPANYLOGINIMG: (state, companyLoginImg) => {
            state.companyLoginImg = companyLoginImg
            localStorage.setItem('companyLoginImg', companyLoginImg)
        },
        // 登录页logo 
        SET_COMPANYLOGINLOGO: (state, companyLoginLogo) => {
            state.companyLoginLogo = companyLoginLogo
            localStorage.setItem('companyLoginLogo', companyLoginLogo)
        },
        // 首页logo 
        SET_COMPANYLOGO: (state, companyLogo) => {
            state.companyLogo = companyLogo
            localStorage.setItem('companyLogo', companyLogo)
        },
        // 登录页标题 
        SET_COMPANYNAME: (state, companyName) => {
            state.companyName = companyName
            localStorage.setItem('companyName', companyName)
        }
    },
    actions: {
        // 获取logo和背景图片
        GetLogoAndName({
            commit
        }) {
            return new Promise((resolve, reject) => {
                adminSystemIndexAPI().then(response => {
                    commit('SET_COMPANYLOGINIMG', response.data.companyLoginImg)
                    commit('SET_COMPANYLOGINLOGO', response.data.companyLoginLogo)
                    commit('SET_COMPANYLOGO', response.data.companyLogo)
                    commit('SET_COMPANYNAME', response.data.companyName)
                    resolve(response)
                }).catch(error => {
                    reject(error)
                })
            })
        },
    }
}

export default init
